TARGET = main_mega
MEGA = 168
MCU_PATH = atm$(MEGA)
DEPEND = $(TARGET).o $(MCU_PATH)/serial.o

CC = avr-gcc
CFLAGS = -Wall -Os -mcall-prologues -mmcu=atmega$(MEGA)
OBJ2HEX = avr-objcopy
AVRDUDE = avrdude
DUDEFLAGS = -c avrispv2 -p m$(MEGA) -P /dev/ttyACM0
FUSEFLAGS = -U lfuse:w:0xe6:m

all: upload

upload: $(TARGET).hex
	$(AVRDUDE) $(DUDEFLAGS) -e
	$(AVRDUDE) $(DUDEFLAGS) $(FUSEFLAGS) -U flash:w:$<

%.hex: %.obj
	$(OBJ2HEX) -R .eeprom -O ihex $< $@

%.obj: $(DEPEND)
	$(CC) $(CFLAGS) $(DEPEND) -o $@

$(DEPEND):
